import _ from 'lodash'
import { RecursiveMenuArray } from '../store/modules/permission'

/** 将数组菜单列表转化为树状关系
 * menus 菜单数组
 *
 */
export function changeMenuArrayToTree(menus) {
  const temps = _.clone(menus)
  // 1.取出pid为根目录的菜单
  const root_menu = _.remove(menus, (route) => {
    return route.pid === '0'
  })
  // 2.进行递归
  RecursiveMenuArray(root_menu, temps)
  return root_menu
}
